package com.matt.service.impl;

import com.matt.domain.ContractProduct;
import com.matt.repository.ContractProductRepository;
import com.matt.service.ContractProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ****************
 * Created by Ron
 * from com.matt
 * on 2018/6/20 0020.
 * *****************
 */
@Service
public class ContractProductServiceImpl implements ContractProductService {

    @Autowired
    private ContractProductRepository contractProductRepository;

    @Override
    public Boolean deleteById(String contractProductId) {
        contractProductRepository.deleteById(contractProductId);
        return true;
    }

    @Override
    public List<ContractProduct> findAll() {
        return contractProductRepository.findAll();
    }

    @Override
    public ContractProduct get(String clienteleId, String id){
        return contractProductRepository.findFirstByClienteleIdAndId(clienteleId, id);
    }

    @Override
    public List<ContractProduct> findByClienteleId(String clienteleId) {
        return contractProductRepository.findAllByClienteleIdOrderByCreatedDesc(clienteleId);
    }

    @Override
    public List<ContractProduct> findByContractId(String contractId) {
        return contractProductRepository.findByContractId(contractId);
    }

    @Override
    public List<ContractProduct> findByProductId(String productId) {
        return contractProductRepository.findByProductId(productId);
    }
}
